Creating Globalized ColdFusion Applications
Table of Contents
- Introduction
- Globalization Changes in ColdFusion MX
- Good Practices: Obstacles in Developing I18N Applications
- Good Practices (cont): Encoding, Unicode, HTML
- Good Practices (cont): Locale Determination, Locale-Specific Formatting, Time Zones
- Good Practices (cont): ResourceBundles,Application Framework, User Specific, Server Specific
Locale Determination
Your application should try to determine a user’s locale transparently.
If your app can't determine the locale or does not yet support it,
your application must provide an appropriate default locale. You can
parse the CGI HTTP_ACCEPT_LANGUAGE variable (which could
contain a semi-colon delimited list of language codes or might possibly
be blank) to try resolving a user’s languages/locales. Another, probably
more accurate approach is to use the incoming client IP to determine
the locale using some sort of geographic location technology, such
as the geoLocatorCFC.
This CFC uses an internal copy of the WHOIS database (contained within
a Java class) and the HTTP_ACCEPT_LANGUAGE CGI variable
to determine an appropriate locale for this user.
It’s important to also provide your users with a way to manually change their locale. No transparent method is foolproof.
Locale-Specific Formatting
The application should display dates, numbers, and currencies in formats specific to the user’s locale. If this locale is one of locales supported by ColdFusion, the application should use the various built-in LS functions. If the locale isn’t supported by ColdFusion, your application should use Java locale specific formatting functionality to handle this in a consistent, standardized way. I don’t recommend building your own locale formatting functionality, let Java worry about that. The I18nFunctionCFC available in the Macromedia Exchange provides functionality similar to the ColdFusion LS functions and is based entirely on underlying Java classes. There are also ICU4J-based CFCs in the Macromedia Exchange that support the major non-Gregorian calendars:
Time Zones
Your application should store datetime data as UTC. This provides
flexibility if you need to distribute your servers across many time
zones or you have the need to cast data to time zones other than the
server’s time zone. For server-specific time zones, use the dateConvert()function
to cast to/from UTC and the GetTimeZoneInfo() to determine
time zone offsets, whether the server is currently in daylight savings,
and so forth. For time zones not specific to the server, you can use timeZoneCFC,
available in the Macromedia Exchange.
Besides simply asking users for their preferred time zone, your application might try to stealthily determine this client-side using JavaScript as shown in this example. Minimally, you might use this technique to limit the number of time zone choices offered to the user or when used in conjunction with geoLocator type technology, specifically pinpoint that time zone offset within that country. This isn’t some fanciful use of technology, sometimes users may not know their time zone.